package com.shine.commonlib;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.shine.commonlibrary.utils.base.BaseActivity;
import com.shine.commonlibrary.utils.testpackage.FragmentOne;
import com.shine.commonlibrary.utils.testpackage.FragmentTwo;
import com.shine.commonlibrary.utils.utils.ToastUtils;
import com.zyyoona7.lib.EasyPopup;
import com.zyyoona7.lib.HorizontalGravity;
import com.zyyoona7.lib.VerticalGravity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity {

    @BindView(R.id.containerOne)
    FrameLayout containerOne;
    @BindView(R.id.containerTwo)
    FrameLayout containerTwo;

    @BindView(R.id.btnOne)
    Button btnOne;
    @BindView(R.id.btnTwo)
    Button btnTwo;
    private EasyPopup mCirclePop;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void init() {
        setFragment(R.id.containerOne, FragmentOne.getInstance(), FragmentOne.class.getSimpleName(), true);
        setFragment(R.id.containerTwo, FragmentTwo.getInstance(), FragmentTwo.class.getSimpleName(), true);
//        ViewCompat.setElevation(btnOne, 2);

        mCirclePop = new EasyPopup(this)
                .setContentView(R.layout.layout_circle_comment)
                .setAnimationStyle(R.style.CirclePopAnim)
                //是否允许点击PopupWindow之外的地方消失
                .setFocusAndOutsideEnable(true)
                //允许背景变暗
                .setBackgroundDimEnable(true)
                //变暗的透明度(0-1)，0为完全透明
                .setDimValue(0.4f)
                //变暗的背景颜色
                .setDimColor(Color.YELLOW)
                //指定任意 ViewGroup 背景变暗
                //.setDimView(viewGroup)
                .createPopup();

        TextView tvZan = mCirclePop.getView(R.id.tv_zan);
        TextView tvComment = mCirclePop.getView(R.id.tv_comment);

        tvZan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("赞");
                mCirclePop.dismiss();
            }
        });

        tvComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("评论");
                mCirclePop.dismiss();
            }
        });
    }

    public void oneFragment(View view) {
        mCirclePop.showAtAnchorView(view, VerticalGravity.CENTER, HorizontalGravity.RIGHT, 0, 0);
    }

    public void twoFragment(View view) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
